package com.yulongtian.weekCompetition.month202302.week02;

import java.util.ArrayList;
import java.util.List;

/**
 * 第 332 场周赛
 * 可
 *
 * @author yulongTian
 * @create 2023-02-12 10:22
 */
public class Test01 {
    public static void main(String[] args) {
        int[] nums = {5, 14, 13, 8, 12};
        System.out.println(findTheArrayConcVal(nums));
    }

    public static long findTheArrayConcVal(int[] nums) {
        long ans = 0L;
        List<Integer> lists = new ArrayList<>(nums.length);
        for (int num : nums) {
            lists.add(num);
        }
        while (true) {
            if (lists.size() >= 2) {
                int a = lists.get(0);
                int b = lists.get(lists.size() - 1);
                lists.remove(lists.size() - 1);
                lists.remove(0);

                Integer value = Integer.valueOf(String.valueOf(a) + String.valueOf(b));
                ans += value;
            } else {
                break;
            }
        }
        if (lists.size() > 0) {
            ans += lists.get(0);
        }
        return ans;
    }
}
